#include <stdio.h>
int you (char n)
{
		int p;
		if (n=='*'||n=='/') p=4;
		if (n=='+'||n=='-') p=3;
		if (n=='(') p=2;
		if (n==')') p=1;
		if (n=='\n') p=0;
		return (p);
}


void main()
{ 
		double c[60],shu1,shu2,shu3,sum=0,b=10;
		char s[60],a,fuhao;
		int top1=0,top2=0,flag=0,flag2=0;
		s[0]='\n';
		printf("请输入一个表达式（以等号结束）\n");
		a=getchar();
		while ((a!='\n'))
		{ 
				if ((a>='0'&&a<='9')||a=='.') 
				{
						flag2=1;
						if (a=='.') flag=1;     
						else {    if (flag==0)    {sum=sum*10+a-48; }
								if (flag==1)    {sum=sum+(a-48)/b; b=b*10; }
						}
				}



				/* if(a>='0'&&a<='9') {top1++;c[top1]=a-48;}*/

				else    { if    (flag2) {top1++,c[top1]=sum; b=10;flag=0;sum=0;flag2=0;}
						switch (a)
						{ case '(':top2=top2+1; s[top2]=a;break;
								case ')': while(s[top2]!='(')
										  { shu1=c[top1];top1--;shu2=c[top1];top1--;fuhao=s[top2];top2--; 
												  switch(fuhao)
												  { case'+':shu3=shu2+shu1;break;
														  case'-':shu3=shu2-shu1;break;
														  case'*':shu3=shu2*shu1;break;
														  case'/':shu3=shu2/shu1;}
																  top1++;c[top1]=shu3;
										  }
										  top2=top2-1;
										  break;
								case'-':;
								case'*':;
								case'/':;
								case'+':
										while ( you(a)<=you(s[top2]))
										{shu1=c[top1];top1--;shu2=c[top1];top1--;fuhao=s[top2];top2--; 
												switch(fuhao)
												{ case'+':shu3=shu2+shu1;break;
														case'-':shu3=shu2-shu1;break;
														case'*':shu3=shu2*shu1;break;
														case'/':shu3=shu2/shu1;}
																top1++;c[top1]=shu3;
										}         
										top2++;s[top2]=a; 

						}
				}
				a=getchar();

		}
		while(top2!=0)
		{shu1=c[top1];top1--;shu2=c[top1];top1--;fuhao=s[top2];top2--; 
				switch(fuhao)
				{ case'+':shu3=shu2+shu1;break;
						case'-':shu3=shu2-shu1;break;
						case'*':shu3=shu2*shu1;break;
						case'/':shu3=shu2/shu1;}
								top1++;c[top1]=shu3;
		}         
		printf("%f",c[top1]); 

}
